#!/bin/ksh

LOGIN=$1
SH_DIR=$2
UP_DIR=$3
UP_FILE=$4

sqlplus -s $LOGIN<<!
DELETE FROM scj.scj_tmp_upload_hardware;
COMMIT;
!

cat > $UP_DIR/ctl/Upload_SCJ_Hardware.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE scj.scj_tmp_upload_hardware
TRAILING NULLCOLS
(
hw_code					  POSITION(01:10)   CHAR		"TRIM(:hw_code)",
network					  POSITION(11:11)   CHAR		"TRIM(:network)",
description 			  POSITION(13:50)   CHAR		"TRIM(:description)"
)
!

/usr/local/bin/dos2unix $UP_DIR/$UP_FILE
sqlldr $LOGIN \
control=$UP_DIR/ctl/Upload_SCJ_Hardware.ctl bad=$UP_DIR/bad/Upload_SCJ_Hardware.bad \
log=$UP_DIR/log/Upload_SCJ_Hardware.log >> $UP_DIR/log/Upload_SCJ_Hardware.log

# Add by ML on 2003 May
sqlplus -s $LOGIN << EOSCRIPTS1
@$SH_DIR/sql/hw_model3g.sql
commit;
disconnect
quit
EOSCRIPTS1
